﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace StateManager
{
    class TitleScreen : GenericMenu
    {

        public TitleScreen()
            : base("Frogger 2011")
        {
            // Create our menu entries.
            MenuItems multiPlayerGameMenuEntry = new MenuItems("MultiPlayer");
            MenuItems singlePlayerMenuEntry = new MenuItems("SinglePlayer");
            MenuItems exitMenuEntry = new MenuItems("Exit");

            // Hook up menu event handlers.
            multiPlayerGameMenuEntry.Selected += MultiPlayerMenuEntrySelected;
            singlePlayerMenuEntry.Selected += SinglePlayerMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(multiPlayerGameMenuEntry);
            MenuEntries.Add(singlePlayerMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        protected override void OnCancel(PlayerIndex playerIndex)
        {
            //ExitScreen();
            //SManager.Game.Exit();
            ConfirmBox confirm = new ConfirmBox("Do you want to exit?");

            confirm.yes += confirmSelectedEvent;
            //confirm.no += cancelSelectedEvent;
            //LoadScreen.Load(SManager, true, e.PlayerIndex, new BackgroundScreen(), new TitleScreen());
            SManager.AddScreen(confirm, ControllingPlayer);
        }

        void confirmSelectedEvent(object sender, PlayerEventHandler e)
        {
            //LoadScreen.Load(SManager, true, e.PlayerIndex, new BackgroundScreen(), new TitleScreen());
            SManager.Game.Exit();
        }

        void MultiPlayerMenuEntrySelected(object sender, PlayerEventHandler e)
        {
            //LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
            //                   new GameplayScreen());

            SManager.AddScreen(new MultiPlayerMenu(), e.PlayerIndex);
        }


        /// <summary>
        /// Event handler for when the Options menu entry is selected.
        /// </summary>
        void SinglePlayerMenuEntrySelected(object sender, PlayerEventHandler e)
        {
            //SManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
            //SManager.AddScreen(new GameScreen(), e.PlayerIndex);
            LoadScreen.Load(SManager, true, e.PlayerIndex, new SingleGameScreen());
        }

        //public void Draw(SpriteBatch sB)
        //{
        //}
    }
}
